package com.gin.no_gay_alliance.callback;

import com.gin.nga.callback.JsonCallback;
import com.gin.nga.exception.NgaClientException;
import com.gin.nga.exception.NgaException;
import com.gin.nga.response.body.BaseMessageBody;
import com.gin.no_gay_alliance.utils.MyHandler;

/**
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2024/1/23 10:23
 **/

public class BaseMessageCallback extends JsonCallback<BaseMessageBody> {
    MyHandler handler;

    public BaseMessageCallback(MyHandler handler) {
        this.handler = handler;
    }

    @Override
    public void onSuccess(BaseMessageBody body) {
        handler.toast(body.getMessage());
    }

    @Override
    public void handleException(NgaException e) {
        super.handleException(e);
        if (e instanceof NgaClientException) {
            handler.toast(((NgaClientException) e).getReason().get(0));
        }
    }
}
